#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
    vector<int> pusheds;
    vector<bool> result;
    stack<int> stacks;
    queue<int> popeds;
    int q, n, i, j, k, t;

    cin >> q;
    result = vector<bool>(q);

    for (i = 0; i < q; i++)
    {
        cin >> n;

        pusheds = vector<int>(n);
        stacks = stack<int>();
        popeds = queue<int>();

        for (j = 0; j < n; j++) 
            cin >> pusheds[j];
        
        for (j = 0; j < n; j++)
        {
            cin >> t;
            popeds.push(t);
        } 
        
        for (j = 0; j < n; j++)
        {
            stacks.push(pusheds[j]);
            while (!stacks.empty() && stacks.top() == popeds.front()) 
            {
                stacks.pop();
                popeds.pop();
            }
        }

        if (stacks.empty())
            result[i] = true;
        else 
            result[i] = false;
    }

    for (i = 0; i < q - 1; i++)
        cout << (result[i] ? "Yes" : "No") << endl;

    cout << (result[q - 1] ? "Yes" : "No");

    return 0;
}
